// 收藏模型
const { Collect } = require('../../../models/collect');
// 商品模型
const { Goods } = require('../../../models/good');
// 统一数据返回类
const { DataReturn } = require('../../../common/returnclass');

module.exports = async (req, res) => {
	// 搜索名称 当前页 当前条数 店铺id 
	let { pagenum,user_id } = req.query;
	console.log(req.query);
	// 查询条数
	let pagesize = 10;

	// 查询所有收藏信息
	let collects = await Collect.find({user_id,is_collect:true}).populate({ 
		path: 'goods_id', 
		model: Goods,
		select: 'goods_imgs goods_name goods_msg_price'
	})
	.skip(pagesize*(pagenum-1))
	.limit(pagesize);
	if (!collects) return DataReturn.getData(res, 200, collects, '暂无收藏数据');
	// 响应
	DataReturn.getData(res, 200, { collects:collects, total: await Goods.find({user_id}).countDocuments() }, '查询收藏列表成功')

}
